using GEM.Application.Common;
using GEM.Application.Dto.Permission;
using GEM.Application.Repositories;
using Microsoft.AspNetCore.Mvc;

namespace GEM.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
public class PermissionController : ControllerBase
{
    private readonly IPermissionService _permissionService;
    public PermissionController(IPermissionService permissionService)
    {
        _permissionService = permissionService;
    }

    [HttpPost("create")]
    public async Task<IActionResult> Create([FromBody] CreatePermissionDto createPermissionDto)
    {
        var isTrue = await _permissionService.CreatePermissionAsync(createPermissionDto.PermissionName);
        return Ok(isTrue);
    }

    [HttpPost("remove")]
    public async Task<IActionResult> Remove([FromBody] RemovePermissionDto removePermissionDto)
    {
        var isTrue = await _permissionService.RemovePermissionAsync(removePermissionDto.PermissionId);
        return Ok(isTrue);
    }

    [HttpGet("paged")]
    public async Task<IActionResult> GetPagedAsync(int pageIndex = 1, int pageSize = 10)
    {
        var result = await _permissionService.GetRolePagedAsync(pageIndex, pageSize);
        return Ok(ApiResponse<PagedResult<PermissionDto>>.Success(result));
    }

    [HttpPost("enable/{id}")]
    public async Task<IActionResult> EnableAsync(Guid id)
    {
        var result = await _permissionService.EnableRoleAsync(id);
        return Ok(result);
    }

    [HttpPost("disable/{id}")]
    public async Task<IActionResult> DisableAsync(Guid id)
    {
        var result = await _permissionService.DisableRoleAsync(id);
        return Ok(result);
    }


}